package database;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class DbConnection {
	
	
	private DbConnection(){};
	private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
	private static Connection conn = null;
	public static Connection getConnection(){
		Properties prop = new Properties();	  
		
		try{
			
			if(conn == null){
				prop.load(new FileInputStream("config.properties"));
				 
	            //get the property value and print it out
	            String dbUrl = prop.getProperty("dburl");
	            String dbUser = prop.getProperty("dbuser");
	            String dbPassword = prop.getProperty("dbpassword");
				//STEP 2: Register JDBC driver
				Class.forName(JDBC_DRIVER);
				//STEP 3: Open a connection
				System.out.println("Connecting to database...");
				conn = DriverManager.getConnection(dbUrl,dbUser,dbPassword);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return conn;
			  
	}
	

}
